<html lang="en-US" xmlns:th = "http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
<link rel="stylesheet" href="../../layui/css/layui.css">
<link rel="stylesheet" href="../../css/common.css">
<script src="../../js/jquery.js"></script>
<body>

<form action="" method="post" class="layui-form">

            <input type="text" id="Id" name="Id" th:value="${good.getId()}" hidden = "hidden" >


    <div class="layui-form-item">
        <label for="name" class="layui-form-label">
            商品名称
        </label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${good.getName}" >
        </div>
    </div>
    <div class="layui-form-item">
        <label for="sellPrice" class="layui-form-label">
            售价
        </label>
        <div class="layui-input-block">
            <input type="text" id="sellPrice" name="sellPrice"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input"  th:value="${good.getSellPrice()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="purPrice" class="layui-form-label">
            进价
        </label>
        <div class="layui-input-block">
            <input type="text" id="purPrice" name="purPrice"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${good.getPurPrice()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="number" class="layui-form-label">
            现存数量
        </label>
        <div class="layui-input-block">
            <input type="text" id="number" name="number"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input" th:value="${good.getNumber()}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="totalPurchase" class="layui-form-label">
            新增数量
        </label>
        <div class="layui-input-block">
            <input type="text" id="totalPurchase" name="totalPurchase"
                   lay-verify="required" lay-vertype="tips"
                   autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label for="type" class="layui-form-label">
            类别
        </label>
        <div class="layui-input-block">
            <select name="type" lay-filter="type" id="type">
                <option value="0">汽水</option>
                <option value="1">零食</option>
                <option value="2">副食</option>
                <option value="3">门票</option>
                <option value="4">小吃</option>
            </select>

        </div>

    </div>

    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-left:0;text-align:center;">

            <button class="layui-btn layui-btn-normal" type="button" onclick="toAjax()">修改</button>
        </div>
    </div>
</form>
<script src="../../layui/layui.js"></script>
<script src="../../js/common.js"></script>
<script>
    var type = 0;
    layui.config({
        base: '/layui/extend/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use(['form', 'layer', 'formSelects', 'dtree'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer
    });


    function toAjax() {

        $.ajax({
            type: "post",
            url: "/goods/updateH/",
            data: {id:$("#Id").val(),name:$("#name").val(),sellPrice:$("#sellPrice").val()
                ,purPrice:$("#purPrice").val(),number:$("#number").val(),totalPurchase:$("#totalPurchase").val()
                ,type:$("#type option:selected").val()},
            dataType: "json",
            success: function (data) {
                if (data.status == '-1') {
                    layer.msg(data.msg, {icon: 5});//失败的表情
                    return ;
                } else if (data.status == '200') {
                    layer.msg(data.msg, {
                        icon: 6,//成功的表情
                        time: 1000,//1秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        location.reload();
                    })
                    return ;
                };
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }
        });
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    };


</script>

</body>
</html>